<template>
  <div id="role_id">
    <div class="menu_top">
      <p class="menu_note">
        注:
        <br />1.增加的新栏目为当前栏目下一行
        <br />2.修改完的栏目一行需保存后提交审批才能生效
      </p>
      <div class="menu_add">
        <el-button size="mini" round @click="add_open">增加</el-button>
      </div>
    </div>
    <el-table :data="Role_list" border style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"></el-table-column>
      <el-table-column prop="rolename" label="角色名称" width="180"></el-table-column>
      <el-table-column prop="status" label="状态" v-slot="$propes">
        <template>
          <el-button type="success" size="mini" round v-if="$propes.row.status === 1">正常</el-button>
        </template>
        <template>
          <el-button type="danger" size="mini" round v-if="$propes.row.status === 2">禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop label="操作" v-slot="$props">
        <el-button type="warning" size="mini" round @click="set_role($props.row)">修改</el-button>
        <el-button type="danger" size="mini" round @click="del_role($props.row.id)">删除</el-button>
      </el-table-column>
    </el-table>
    <Addrole ref="add_role_ref" @reload_role="reload_role" :isShow="isShow"></Addrole>
  </div>
</template>

<script>
import { mapActions, mapState, mapMutations } from "vuex";
import Addrole from "../views/Addrole.vue";
export default {
  data() {
    return {
      isShow: { flig: false }
    };
  },
  created() {
    this.RoleActions();
  },
  methods: {
    ...mapActions("RoleStory", ["RoleActions"]),
    ...mapMutations("RoleStory", ["RoleMutations"]),
    add_open() {
      this.isShow.flig = true;
    },
    reload_role() {
      this.RoleActions();
    },
    del_role(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });

          this.$http.post("/roledelete", { id }).then(res => {
            if (res.code == 200) {
              this.RoleActions();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    set_role(obj){
        this.isShow.flig=true
        this.$refs.add_role_ref.setForm(obj)
    }
  },
  computed: {
    ...mapState({ Role_list: state => state.RoleStory.Role_list })
  },
  components: {
    Addrole
  }
};
</script>

<style>
#role_id .menu_top {
  display: flex;
  justify-content: space-between;
}
#role_id .menu_note {
  font-size: 12px;
  color: #c4c4c4;
  text-align: left;
}
#role_id .menu_add > button {
  width: 80px;
  color: #ff5d3e;
  background-color: white;
  text-align: center;
}
</style>